<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>药库缺药</title>
</head>
<body>
	<div class="easyui-tabs" style="height: 100%; width: 100%">
		<div title="缺药管理" style="display: none;"
			data-options="iconCls:'icon-add'">
			<div style="height: 100%; width: 100%">
				<div id="SSQueyao_GridToolbar" style="padding-left: 5px">
					<input class="easyui-searchbox" id="SSLackDrugByDrugName"
						data-options="width:200,prompt:'请输入药品名'"> <span
						style="padding-left: 10px">药品类<select 
						class="easyui-combobox" id="SSLackDrugmMedcineType"
						data-options="url:'getAllMedcineType',width:100,textField:'medcineTypeName',valueField:'medcinetypeId',method:'get',panelHeight:'auto'">
					</select>
					</span> <span style="padding-left: 10px"> 登记人:<select
						class="easyui-combobox" id="SSLackDrugStaffId"
						data-options="width:200,url:'getAllStaff',method:'get',valueField:'staffId',textField:'staffname',panelHeight:'auto'"></select>
					</span>
					<span style="padding-left:10px">
						<a id="searchSSLackDrugBySome" class="easyui-linkbutton" data-options="iconCls:'icon-search'" id="searchSSQueyao">查找</a>
					</span>
					<span style="padding-left:10px">
						<a id="addNewSSLackDrugBtn" class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增缺药</a>
					</span>
					<span style="padding-left:10px">
						<a id="deleteSSLackDrugBtn" class="easyui-linkbutton" data-options="iconCls:'icon-no'">删除缺药</a>
					</span>
					<span style="padding-left:10px">
						添加到下一批采购单 <a id="addNewSSPlanBuyDrugs" data-options="iconCls:'icon-add'" class="easyui-linkbutton">添加</a>
					</span>
				</div>
				<table id="SSLackDrugGrid" class="easyui-datagrid" style="width:100%;height:100%" data-options="rownumbers:true,url:'getAllSSQueYao_Map',method:'get',fitColumns:true,toolbar:'#SSQueyao_GridToolbar',pagination:true">
					<thead>
						<tr>
							<th data-options="field:'drugstorageLackdrugsId',width:50,align:'center',checkbox:true">缺药编号</th>
							<th data-options="field:'medcineName',width:200,align:'center'">药品名称</th>
							<th data-options="field:'medcineTypeName',width:50,align:'center'">药品类名</th>
							<th data-options="field:'medcineNumber',width:70,align:'center'">缺药数量</th>
							<th data-options="field:'medcineCost',width:100,align:'center'">总花费</th>
							<th data-options="field:'staffname',width:150,align:'center'">登记人</th>
							<th data-options="field:'medcineNote',width:250">备注</th>
						</tr>
					</thead>
				</table>
			</div>
			<div id="SSLackDrugWin" class="easyui-window" data-options="title:'新增缺药',
					width:556,
					height:273,
					iconCls:'icon-add',
					closed:true,
					modal:true,
					border:'thick',
					draggable:false,
					resizable:false">
					<form id="addNewSSLackDrugForm" action="addNewSSLackDrugForm" method="post">
						<table style="width:100%;height:80%">
							<tr>
								<td>
									药品名称 <select name="medcineId" class="easyui-combobox" data-options="width:150,valueField:'medcineId',textField:'medcineName',url:'getAllMedcineDetailList',method:'get',value:1"></select>
								</td>
								<td>
									药品数量 <input name="medcineNumber"  class="easyui-numberbox" data-options="width:150,required:true" min="1"
										max="10000" >
								</td>
							</tr>
							<tr>
								<td>
									登记人
									<span style="padding-left:10px">
									<select name="staffId" class="easyui-combobox" 
											data-options="width:150,url:'getAllStaff',method:'get',valueField:'staffId',textField:'staffname',panelHeight:'auto',value:1"></select>
									</span>
								</td>
								<td>
									备注
									<span style="padding-left:25px">
									<input name="note" class="easyui-textbox" data-options="width:150,prompt:'速度补充该种药品!'">
									</span>
								</td>
							</tr>
						</table>
						<div style="height:20%;width:100%;padding-left:425px">
							<a id="addNewSSLackDrug_Yes" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定</a>
						</div>
					</form>
					</div>
					<div class="easyui-window" 
						 id="addNewSSBuyDrugs"
						 data-options="title:'下一批购药单',
								width:632,
								height:336,
								iconCls:'icon-add',
								closed:true,
								modal:true,
								border:'thick',
								resizable:false">
								<div id="addNewSSBuyDrugsWinToolbar" style="padding-left:5px">
									打开后请先刷新表格
									<input class="easyui-searchbox" data-options="width:200,prompt:'请输入药品名称'">
								</div>
							<div id="nextSSPlanBuyDrug" style="width:100%;height:100%">
								<table style="height:100%;width:100%;padding:10px" class="easyui-datagrid" 
										data-options="toolbar:'#addNewSSBuyDrugsWinToolbar',rownumbers:true,url:'getAllSSBuyDrugDetail',method:'get',fitColumns:true,pagination:true">
									<thead>
										<tr>
											<th data-options="field:'drugStorageId',align:'center',width:50">编号</th>
											<th data-options="field:'medcineName',width:100,align:'center'">药品名称</th>
											<th data-options="field:'allbuymedcineName',wdith:100,align:'center'">采购单名</th>
											<th data-options="field:'medcineNumber',width:200,align:'center'">药品数量</th>
										</tr>
									</thead>
								</table>
							</div>
					</div>
		</div>
		<div title="缺药统计" data-options="iconCls:'icon-add',closable:true"
			style="overflow: auto; display: none;"></div>
		<div title="打印报告" data-options="iconCls:'icon-add',closable:true"
			style="display: none;"></div>
	</div>
	<script>
		$(function(){
			//新增药库缺药表单
			$("#addNewSSLackDrugForm").form({
				onSubmit : function(){
					return $(this).form('validate');
				},
				success : function(){
					$("#SSLackDrugWin").window('close');
					$("#SSLackDrugGrid").datagrid('load');
					$("#addNewSSLackDrugForm").form('clear');
					$.messager.alert('提示','新增缺药成功');
				}
			});
			//确定新增药库缺药按钮
			$("#addNewSSLackDrug_Yes").linkbutton({
				onClick : function(){
					console.log("dsd");
					$("#addNewSSLackDrugForm").submit();
				}
			});
			//新增缺药按钮
			$("#addNewSSLackDrugBtn").linkbutton({
				onClick : function(){
					$("#SSLackDrugWin").window('open');
				}
			});
			//按条件查询相关缺药信息
			$("#searchSSLackDrugBySome").linkbutton({
				onClick : function(){
					var medcineTypeId = $("#SSLackDrugmMedcineType").combobox('getValue');
					var staffId = $("#SSLackDrugStaffId").combobox("getValue");
					$("#SSLackDrugGrid").datagrid('load','getSSLackDrugBySome?medcineTypeId='+medcineTypeId+"&staffId="+staffId);
					$("#SSLackDrugmMedcineType").combobox('setValue','');
					$("#SSLackDrugStaffId").combobox('setValue','');
				}
			});
			//按药品名称查询
			$("#SSLackDrugByDrugName").searchbox({
				searcher : function(value,name){
					$("#SSLackDrugByDrugName").searchbox('setValue','');
					$("#SSLackDrugGrid").datagrid('load','querySSLackDrugByDrugName?medcineName='+value);
				}
			});
			//删除药品缺药信息
			$("#deleteSSLackDrugBtn").linkbutton({
				onClick : function(){
					var rows = $("#SSLackDrugGrid").datagrid('getChecked');
					if(rows.length!=0){
						var drugsName = "";
						var SSLackDrugId ="";
						for(var i=0;i<rows.length;i++){
							drugsName+=rows[i].medcineName+":"+rows[i].medcineNumber+",";
							SSLackDrugId+=rows[i].drugstorageLackdrugsId+"-";
						}
						console.log(SSLackDrugId);
						$.messager.confirm('提示','是否将:'+drugsName+"删除!",function(r){
							if(r){
								$.get("deleteSSLackDrug?SSLackDrugId="+SSLackDrugId+"",function(r){
									$.messager.alert('提示','已成功删除');
									$("#SSLackDrugGrid").datagrid('load');
								});
							}
						});
					}else{
						$.messager.alert('提示','请选择你要删除的行!');
					}
				}
			});
			//添加到下一批采购订单中
			$("#addNewSSPlanBuyDrugs").linkbutton({
				onClick : function(){
					var rows = $("#SSLackDrugGrid").datagrid('getChecked');
					if(rows.length!=0){
						var drugsName="";
						var SSLackDrugId ="";
						var medcineName="";
						var medcineNumber="";
						for(var i=0;i<rows.length;i++){
							drugsName+=rows[i].medcineName+":"+rows[i].medcineNumber+",";
							SSLackDrugId+=rows[i].drugstorageLackdrugsId+"-";
							medcineName+=rows[i].medcineName+"-";
							medcineNumber+=rows[i].medcineNumber+"-";
						}
							console.log(medcineName+medcineNumber);
							$.messager.confirm('提示','是否将 '+drugsName+'添加到下一批采购单中',function(r){
								if(r){
									//计划采购详情新增
									$.get('addNewSSBuyDrugDetail?medcineName='+medcineName+""+"&medcineNumber="+medcineNumber+"",function(r){
										$.get("deleteSSLackDrug?SSLackDrugId="+SSLackDrugId+"",function(r){
											$("#SSLackDrugGrid").datagrid('load');
											$("#addNewSSBuyDrugs").window('open');
											$("#nextSSPlanBuyDrug").datagrid('load','getAllSSBuyDrugDetail');
										});
										
									});
								}
							});
						}else{
							$.messager.alert('提示','请选择要添加到下一批购药的行');
					}
				}
			});
		});
	</script>
</body>
</html>